// pages/settle/settle.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    originName:'',
    originTime:'',
    terminusName:'',
    terminusTime:'',
    day:"",
    month:"",
    linkman: false,
    age:'',
    name:'',
    number:'',
    phone:''
  },

  linkmanAdd(){
    wx.navigateTo({
      url: '/pages/linkman/linkman',
    })
  },

  infare() {
    try {
      const {originName, originTime, terminusName, terminusTime, day, month, name, number, phone} = this.data;
      wx.setStorageSync('infare', { originName, originTime, terminusName, terminusTime, day, month, name, number, phone });
      
      // 先显示购买成功提示
      wx.showToast({
        title: '购买成功',
        icon: 'success',
        duration: 1000,
        success: () => {
          // 提示显示完成后跳转
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/going/goimg',
            });
          }, 1500);
        }
      });
      
    } catch (err) {
      console.error('操作失败:', err);
      wx.showToast({
        title: '购买失败',
        icon: 'none'
      });
    }
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
    this.setData({
      originName: options.originName,
      originTime: options.originTime,
      terminusName: options.terminusName,
      terminusTime: options.terminusTime,
      month: options.month,
      day: options.day,
    });
  },

  onShow(){
    const linkman = wx.getStorageSync('linkman');
    if (linkman) {
        this.setData({
            linkman: true,
            age: linkman.age, 
            name: linkman.name,  
            number: linkman.number,
            phone: linkman.phone
        });
    } else {
        this.setData({
          linkman: false
        });
    }
  },
})